﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System.Windows.Input;
using BrainTechLLC.ImageOperators;

namespace ImageAppViewModels
{
    public partial class MoveFilter : RoutedCommand, ICommand
    {
        public bool CanExecute(FilterCollectionViewModel collectionVM, FilterViewModel filterVM, Direction dir)
        {
            int found;

            switch (dir)
            {
                case Direction.Left:
                case Direction.Up:
                    found = collectionVM.FindIndex(filterVM);
                    return (found != 0);

                case Direction.Right:
                case Direction.Down:
                    found = collectionVM.FindIndex(filterVM);
                    return (found < collectionVM.Count - 1);
            }

            return true;
        }

        public void ExecuteCommand(FilterCollectionViewModel collectionVM, FilterViewModel filterVM, Direction dir)
        {
            switch (dir)
            {
                case Direction.Left:
                    collectionVM.MoveItemLeft(filterVM);
                    break;

                case Direction.Right:
                    collectionVM.MoveItemRight(filterVM);
                    break;

                case Direction.Up:
                    collectionVM.MoveItemLeftAll(filterVM);
                    break;

                case Direction.Down:
                    collectionVM.MoveItemRightAll(filterVM);
                    break;
            }
        }        
    }

}
